package com.xqb.modules.controller.course;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.LesSubject;
import com.xqb.modules.service.ILesSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 题目Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/course/subject")
public class LesSubjectController extends BaseController
{
    @Autowired
    private ILesSubjectService lesSubjectService;

    /**
     * 查询题目列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(LesSubject lesSubject)
    {
        startPage();
        List<LesSubject> list = lesSubjectService.selectLesSubjectList(lesSubject);
        return getDataTable(list);
    }

    /**
     * 导出题目列表
     */
    @PreAuthorize("@ss.hasPermi('course:subject:export')")
    @Log(title = "题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesSubject lesSubject)
    {
        List<LesSubject> list = lesSubjectService.selectLesSubjectList(lesSubject);
        ExcelUtil<LesSubject> util = new ExcelUtil<LesSubject>(LesSubject.class);
        util.exportExcel(response, list, "题目数据");
    }

    /**
     * 获取题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lesSubjectService.selectLesSubjectById(id));
    }

    /**
     * 新增题目
     */
    @PreAuthorize("@ss.hasPermi('course:subject:add')")
    @Log(title = "题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LesSubject lesSubject)
    {
        return toAjax(lesSubjectService.insertLesSubject(lesSubject));
    }

    /**
     * 修改题目
     */
    @PreAuthorize("@ss.hasPermi('course:subject:edit')")
    @Log(title = "题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesSubject lesSubject)
    {
        return toAjax(lesSubjectService.updateLesSubject(lesSubject));
    }

    /**
     * 删除题目
     */
    @PreAuthorize("@ss.hasPermi('course:subject:remove')")
    @Log(title = "题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lesSubjectService.deleteLesSubjectByIds(ids));
    }
}
